/*
 * 文 件 名:  AbstractIbatisDAO.java
 * 版    权: MIT  1993-2013,  All rights reserved
 * 描    述:  ibatis的数据库操作DAO
 * 修 改 人:  aganzhoul
 * 修改时间:  2013-1-22
 */
package com.hfut.jpoa.common.dao;

import com.ibatis.sqlmap.client.SqlMapClient;

import java.sql.Connection;
import java.sql.SQLException;

import javax.annotation.Resource;
import javax.sql.DataSource;


/**
 * ibatis的数据库操作DAO
 * 
 * @author aganzhoul
 * @version [1.0, 2013-1-21]
 * @since [基础框架/1.0]
 */
public abstract class AbstractIbatisDao {
    @Resource
    protected SqlMapClient sqlMapClient; 
    
    public SqlMapClient getSqlMapClient() {
        return sqlMapClient;
    }
    
    public void setSqlMapClient(SqlMapClient sqlMapClient) {
        this.sqlMapClient = sqlMapClient;
    }
    
    /**
     * 获取数据库连接
     * 
     * @return 数据库连接
     * @throws SQLException
     */
    public Connection getConnection()
        throws SQLException {
        return sqlMapClient.getDataSource().getConnection();
    }
    
    /**
     * 获取事务中的当前连接
     * 
     * @return 数据库连接
     * @throws SQLException
     */
    public Connection getCurrentConnection()
        throws SQLException {
        return sqlMapClient.getCurrentConnection();
    }
    
    /**
     * 获取数据源
     * 
     * @return 数据源
     */
    public DataSource getDataSource() {
        return sqlMapClient.getDataSource();
    }
    
}
